
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports _2bMatesSite.BO

Namespace _2bMatesSite
	''' <summary>
	''' Summary description for music_page.
	''' </summary>
	Public Class music_page
		Inherits BaseWebPage
		Protected hlUser1MusicLink2 As System.Web.UI.WebControls.HyperLink
		Protected Hyperlink3 As System.Web.UI.WebControls.HyperLink
		Protected Hyperlink4 As System.Web.UI.WebControls.HyperLink
		Protected Hyperlink8 As System.Web.UI.WebControls.HyperLink
		Protected Hyperlink9 As System.Web.UI.WebControls.HyperLink
		Protected dgMusicUsers As System.Web.UI.WebControls.DataGrid
		Protected lblNoUsers As System.Web.UI.WebControls.Label
		Protected hlUser1MusicLink3 As System.Web.UI.WebControls.HyperLink

		Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
			' Put user code to initialize the page here
			Me.pageTemplate.PageTitle = PageTitles.MUSIC_PAGE
			If LoggedUser = Nothing Then
				Response.Redirect(Constants.LOGIN_PAGE)
			End If
			If Not Me.IsPostBack Then
				BindGrid()
			End If
		End Sub

		Protected Function CreateDataSource() As ICollection
			Dim usr As BO.User = Me.LoggedUser

			Dim i As Integer = 0

			Dim dt As New DataTable()
			'ArrayList usersFound = Users.FindRandomNetworkedUsersWithSongURL(LoggedUser.ID,4,3,true);
			Dim usersFound As New ArrayList()
			Dim tmpUser As User = Nothing
			i = 0
			While i < Constants.arrMusiciansIDs.Length
				tmpUser = Users.GetUserByID(Constants.arrMusiciansIDs(i))
				If tmpUser <> Nothing Then
					usersFound.Add(tmpUser)
				End If
				System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
			End While

			If usersFound.Count <= 0 Then
				lblNoUsers.Visible = True
				dgMusicUsers.Visible = False
			Else
				Dim pic As Picture
				Dim dr As DataRow

				dt.Columns.Add(New DataColumn("UserName", GetType(String)))
				dt.Columns.Add(New DataColumn("MemberURL", GetType(String)))
				dt.Columns.Add(New DataColumn("PhotoURL", GetType(String)))
				dt.Columns.Add(New DataColumn("MusicLinkURL", GetType(String)))
				dt.Columns.Add(New DataColumn("MusicLinkName", GetType(String)))
				dt.Columns.Add(New DataColumn("MusicLinkVisible", GetType(Boolean)))
				dt.Columns.Add(New DataColumn("MusicLinkURL2", GetType(String)))
				dt.Columns.Add(New DataColumn("MusicLinkName2", GetType(String)))
				dt.Columns.Add(New DataColumn("MusicLinkVisible2", GetType(Boolean)))
				dt.Columns.Add(New DataColumn("MusicLinkURL3", GetType(String)))
				dt.Columns.Add(New DataColumn("MusicLinkName3", GetType(String)))
				dt.Columns.Add(New DataColumn("MusicLinkVisible3", GetType(Boolean)))

				dt.Columns.Add(New DataColumn("ItemHeight", GetType(String)))
				'				// List search results
'				foreach ( NetworkFriend result in usersFound )
'				{
'					dr = dt.NewRow();
'
'					dr[0] = getNameBeginning(result.Friend.Name);
'					dr[1] = "../" + Constants.MEMBERS + "?id=" + result.Friend.ID;
'					pic = result.Friend.DefaultPicture;
'					if (pic != null)
'					{
'						dr[2] = Pictures.GetPictureSrcFullURL(pic, true, "../");
'					}
'					else
'					{
'						dr[2] = Constants.DEFAULT_THUMBNAIL_IMAGE_URL;	
'					}
'					if(result.Friend.SongURL1 != null && result.Friend.SongURL1 != "")
'					{
'						dr[3] = this.constructMusicURL(result.Friend.SongURL1);
'						dr[4] = result.Friend.SongURL1;
'						if(result.Friend.SongURLName1 != null && result.Friend.SongURLName1 != "")
'							dr[4] = result.Friend.SongURLName1;
'					}
'					else if(result.Friend.SongURL2 != null && result.Friend.SongURL2 != "")
'					{
'						dr[3] = this.constructMusicURL(result.Friend.SongURL2);
'						dr[4] = result.Friend.SongURL2;
'						if(result.Friend.SongURLName2 != null && result.Friend.SongURLName2 != "")
'							dr[4] = result.Friend.SongURLName2;
'
'					}
'					else if(result.Friend.SongURL3 != null && result.Friend.SongURL3 != "")
'					{
'						dr[3] = this.constructMusicURL(result.Friend.SongURL3);
'						dr[4] = result.Friend.SongURL3;
'						if(result.Friend.SongURLName3 != null && result.Friend.SongURLName3 != "")
'							dr[4] = result.Friend.SongURLName3;
'
'					}
'
'					dt.Rows.Add(dr);
'				}
'			}
'			

				Dim cnt As Integer = 0
				For Each result As User In usersFound
					dr = dt.NewRow()

					dr(0) = result.Name
					dr(1) = "../" + Constants.MEMBERS + "?id=" + result.ID
					pic = result.DefaultPicture
					If pic <> Nothing Then
						dr(2) = Pictures.GetPictureSrcFullURL(pic, True, "../")
					Else
						dr(2) = Constants.DEFAULT_THUMBNAIL_IMAGE_URL
					End If
					If result.SongURL1 <> Nothing AndAlso result.SongURL1 <> "" Then
						dr(3) = Me.constructMusicURL(result.SongURL1)
						dr(4) = result.SongURL1
						If result.SongURLName1 <> Nothing AndAlso result.SongURLName1 <> "" Then
							dr(4) = result.SongURLName1
						End If
						dr(5) = True
					Else
						dr(3) = ""
						dr(4) = ""
						dr(5) = False
					End If
					If result.SongURL2 <> Nothing AndAlso result.SongURL2 <> "" Then
						dr(6) = Me.constructMusicURL(result.SongURL2)
						dr(7) = result.SongURL2
						If result.SongURLName2 <> Nothing AndAlso result.SongURLName2 <> "" Then
							dr(7) = result.SongURLName2
						End If
						dr(8) = True
					Else
						dr(6) = ""
						dr(7) = ""
						dr(8) = False
					End If
					If result.SongURL3 <> Nothing AndAlso result.SongURL3 <> "" Then
						dr(9) = Me.constructMusicURL(result.SongURL3)
						dr(10) = result.SongURL3
						If result.SongURLName3 <> Nothing AndAlso result.SongURLName3 <> "" Then
							dr(10) = result.SongURLName3
						End If
						dr(11) = True
					Else
						dr(9) = ""
						dr(10) = ""
						dr(11) = False
					End If

					dr(12) = Constants.arrMusiciansBoxHeight(cnt)
					System.Math.Max(System.Threading.Interlocked.Increment(cnt),cnt - 1)

					dt.Rows.Add(dr)
				Next
			End If
			Dim dv As New DataView(dt)
			Return dv
		End Function

		Protected Sub BindGrid()
			'init datagrid with database data ordered param
			dgMusicUsers.DataSource = CreateDataSource()
			dgMusicUsers.DataBind()
		End Sub

		#region Web Form Designer generated code
		Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
			'
			' CODEGEN: This call is required by the ASP.NET Web Form Designer.
			'
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()
			AddHandler Me.Load, AddressOf Me.Page_Load

		End Sub
#End Region
	End Class
End Namespace






